//var url=document.URL;
var para = "";
//var fjid = [];
//var price = 0;//初始化所有房源平均的租售一天一平米多钱。
//var zj = 0;//初始化此房源总价
var shu = 1; //初始化显示第一页
var pagesize = 3; //上拉加载数据
//var commname;
var ssqy = "HM";
var building3dNo; //记录楼盘编号
var promisemodellczx; //乐成中心新增的一栋楼图层
var htmlUrl = document.location.host;
var port = document.location.port;
var houseInfo = {};
if (htmlUrl == "") {
  htmlUrl = "http://localhost:" + port;
} else {
  htmlUrl = "http://" + htmlUrl;
}
var url = document.URL;

var array2;
var btncount = 1; //全局变量用来记录是全景周边还是3d楼盘
var promisemodelhm; //初始化模型层
var promisemodel; //模型层
var promisehouse = ""; //户层
var imageryLayers; //影像图层
var Range = 350; //
var Value = 202; //确定滑块位置
var array1 = [];
var array = [];
var smid1;
var resu1;
var viewer;
var roomNo;
//var path = htmlUrl+"/ZSXT/";
//房源中的收藏
ajax(
  "/api/v1/user/opt/houseCollectionNum",
  "POST",
  { houseId: houseid },
  function(result) {
    if (result.code == 200) {
      $("#shoucang").html(result.data + "人收藏");
    }
  },
  false
);
//点击收藏按钮
$("#shoucangfy").click(function() {
  var cookie = getCookie("signature");
  if (cookie) {
    if ($("#sfsc").html() == "已收藏") {
      ajax(
        "/api/v1/user/opt/delCollection",
        "POST",
        { houseId: houseid },
        function(result) {
          $("#sfsc").html("收 藏");
        },
        false
      );
    } else {
      ajax(
        "/api/v1/user/opt/addCollection",
        "POST",
        { houseId: houseid },
        function(result) {
          $("#sfsc").html("已收藏");
        },
        false
      );
    }
  } else {
    window.location.href = "/console/#/Login";
  }
});
var buildingId = "";
if(brochureId != ""&&brochureId !=null){
			ajax("/api/v1/brochure/brochureUserInfo",'post',{brochureId:brochureId},function(result){
				if(result.code == 200){
					$("#phone").attr("data-original-title",result.data.phone);
 document
        .getElementById("phone")
        .setAttribute("href", "tel:" + result.data.phone);
				}
			   },false);
		}
//房源信息
ajax(
  "/api/v1/building/houseInfo",
  "POST",
  { houseId: houseid },
  function(result) {
    if (result.code == 200) {
      houseInfo.title = result.data.houseTitle;
      houseInfo.desc = result.data.address;
      if (result.data.longitude) {
        longitude = result.data.longitude;
      }
      if (result.data.latitude) {
        latitude = result.data.latitude;
      }
      buildingId = result.data.buildingId;
      building3dNo = result.data.building3dNo;
      var address = result.data.address; //地址
      var name = result.data.buildingName; //楼盘名称
      var lpdz1 = result.data.buildingAddress; //楼盘地址
      var kfs = result.data.developer; //开发商
      var title = result.data.houseTitle; //房源标题
      var lpjs = result.data.introduce; //房源荐语
      var qzsj = result.data.hireTime; //起租时间
      var zxqk = result.data.fitmentStatus; //装修状况：1：毛坯；2：标配简装；3：遗留装修
      if (zxqk == 4) {
        $("#zxqk").html("拎包入住");
      } else if (zxqk == 1) {
        $("#zxqk").html("毛坯");
      } else if (zxqk == 2) {
        $("#zxqk").html("标配简装");
      } else if (zxqk == 3) {
        $("#zxqk").html("遗留装修");
      }
      var szhx = result.data.loopName; //所在环线
      var phone = result.data.phone; //发布人电话
      var price = result.data.price; //单价：元/平米每天
      var area = result.data.area; //面积
    
if(price == 0){
$("#danjia").html("暂无");
}else{
  var zj = (price * 30 * area) / 10000;
      $("#pj").html(zj.toFixed(1));
}
      var sjsj = result.data.releaseTime; //上架时间
      if (sjsj != null && sjsj != "null") {
        var sjs = sjsj.substring(0, sjsj.length - 9);
        $("#sjsj").html("上架：" + sjs);
      }
      roomNo = result.data.roomNo; //房号
      var zdzq = result.data.minTenancy; //最短租期
      var jzmj = result.data.totalArea; //总面积
      var gdbgj = result.data.separationNum; //隔断办公间数量
      var zglc = result.data.totalFloors; //最大楼层
      //result.data.townName;//区县名称
      //result.data.tradingArea;//商圈
      var ya = result.data.deposit; //付款方式压几个月
      var fu = result.data.payment; //付款方式付几个月的
      var sssq = result.data.tradingName; //商圈名称
      var gwzx = result.data.minStation; //可容纳最小工位数
      var gwzd = result.data.maxStation; //可容纳最大工位数
      var sfkzc = result.data.registerFlag; //是否注册公司 0否 1是
      var chaoxiang = result.data.orientation; //朝向 0东 1南 2西 3北
      var lptp = result.data.buildingImg; //楼盘图片
      var jcnd = result.data.buildingYear; //建成年代
      var ldsl = result.data.totalNum; //栋数
      var temp = latitude + "," + longitude;
      var bd =
        "http://api.map.baidu.com/direction?origin=latlng:" +
        temp +
        "|name:我的位置&destination=" +
        result.data.address +
        "&mode=driving&region=北京&output=html&src=webapp.baidu.openAPIdemo";
      //window.location.href = 'http://api.map.baidu.com/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&output=html&src=webapp.baidu.openAPIdemo';
      document.getElementById("daohang1").setAttribute("href", bd);
      //document.getElementById("daohang1").setAttribute('href',"baidu.html?name="+address);
     
      $("#lpdz").html(address);
      $("#title").html(title);
      $("#mianji").html(area);
      $("#price").html(price);
      $("#roomNo").html(roomNo);
      $("#zj").html(zj);
      $("#qzsj").html(qzsj);
      //$("#zxqk").html(zxqk);
      $("#zdzq").html(zdzq + "个月");
      $("#gdbgj").html(gdbgj);
      $("#fkfs").html("押" + ya + " 付" + fu);
      $("#krngw").html(gwzx + "~" + gwzd);
      if (sfkzc == "0") {
        $("#sfkzc").html("否");
      } else {
        $("#sfkzc").html("是");
      }
      //$("#sfkzc").html(sfkzc);
      var te = chaoxiang.replace("0", "东");
      var tem = te.replace("1", "南");
      var temp = tem.replace("2", "西");
      var chaox = temp.replace("3", "北");
      $("#chaoxiang").html(chaox);
if(brochureId == ""||brochureId ==null){
					$("#phone").attr("data-original-title",phone);
 document
        .getElementById("phone")
        .setAttribute("href", "tel:" + result.data.phone);
				}
      $("#lpjs").html(lpjs);
      $("#jcnd").html(jcnd + "年");
      $("#jzmj").html(jzmj + "m²");
      $("#sssq").html(sssq);
      $("#ldsl").html(ldsl + "栋");
      $("#szhx").html(szhx);
      $("#zglc").html(zglc + "层");
      $("#kfs").html(kfs);
      $("#lpdz1").html(lpdz1);
      $("#name").html(name);
      $("#lptp").attr("src", lptp);
      $("#subwayDistanceName").html(result.data.subwayDistanceName);
      var imgurl1 = fwurl + "/image/";
      var Visits; //浏览量量
      var yzx; //月咨询
      var jjryzx; //经纪人月咨询
      //浏览量
      ajax(
        "/api/v1/user/opt/countVisit",
        "POST",
        { id: result.data.buildingId, type: 1 },
        function(result) {
          if (result.code == 200) {
            Visits = result.data;
          }
        },
        false
      );
      yzx = 0;
      //月咨询
      function getStats(type,id){
        var userId = result.data.corrId;
        if(type==1){
          userId = result.data.corrId;
        }else if(type==2){
          userId = result.data.corrId;
        }else if(type==3){
          userId = result.data.corrId;
        }
        ajax(
          "/api/v1/consult/stats",
          "POST",
          { type: type, resourceId: userId },
          function(result) {
            if (result.code == 200) {
              yzx = result.data.num;
            }
          },
          false
        );
      }
      if (result.data.companyType == 1) {
        getStats(3)
        //开发商
        ajax(
          "/api/v1/company/companyInfo",
          "POST",
          { companyId: result.data.corrId },
          function(result) {
            if (result.code == 200) {
              setTimeout(function(){
                var logo;
                if (
                  result.data.companyLogo == null ||
                  result.data.companyLogo == "null"
                ) {
                  logo = "static/images/noupload.png";
                } else {
                  logo = imgurl1 + result.data.companyLogo;
                }
                var html =
                  '<div class="main-info main-info-shadow aui-clearfix" style="padding:.4rem;" onclick="toDevelopers()">' +
                  '<div class="aui-pull-left" style="width:15%;height: 2rem;">' +
                  '<img src="' +
                  logo +
                  '" style="width:80%;">' +
                  "</div>" +
                  '<div class="aui-pull-right" style="width:84%;">' +
                  '<div class="aui-info">' +
                  '<div class="aui-info-item">' +
                  '<h4 class="title" style="font-size:.8rem;width:7.5rem;overflow:hidden;text-overflow:ellipsis;white-space: nowrap; !important;display:inline-block;">' +
                  result.data.companyName +
                  '</h4><small class="blue-small-tag lightpurple">开发商</small>' +
                  "</div>" +
                  '<div class="aui-info-item"><small>浏览量' +
                  Visits +
                  "</small></div>" +
                  "</div>" +
                  '<div class="aui-info">' +
                  '<div class="aui-info-item"><small>发布中房源：' +
                  result.data.companyHouseNum +
                  "（近三个月发布" +
                  result.data.quarterNum +
                  "）</small></div>" +
                  '<div class="aui-info-item"><small>月咨询' +
                  yzx +
                  "</small></div>" +
                  "</div>" +
                  "</div>" +
                  "</div>";
                $("#fbf").append(html);
              },1000)
            }
          },
          false
        );
      } else if (result.data.companyType == 2) {
        getStats(2)
        //资产管理公司
        ajax(
          "/api/v1/company/companyInfo",
          "POST",
          { companyId: result.data.corrId },
          function(result) {
            if (result.code == 200) {
              var html =
                '<div class="main-info main-info-shadow aui-clearfix" style="padding:.4rem;" onclick="toAsset(\'' +
                result.data.companyId +
                "')\">" +
                '<div class="aui-pull-left" style="width:15%;height: 2rem;">' +
                '<img src="' +
                getDefaultImg(result.data.companyLogo) +
                '" style="width:80%;">' +
                "</div>" +
                '<div class="aui-pull-right" style="width:84%;">' +
                '<div class="aui-info">' +
                '<div class="aui-info-item">' +
                '<h4 class="title" style="font-size:.8rem;width:7.5rem;overflow:hidden;text-overflow:ellipsis;white-space: nowrap; !important;display:inline-block;">' +
                result.data.companyName +
                '</h4><small class="blue-small-tag lightblue">资产管理公司</small>' +
                "</div>" +
                '<div class="aui-info-item"><small>浏览量' +
                Visits +
                "</small></div>" +
                "</div>" +
                '<div class="aui-info">' +
                '<div class="aui-info-item"><small>发布中房源：' +
                result.data.companyHouseNum +
                "（近三个月发布" +
                result.data.quarterNum +
                "）</small></div>" +
                '<div class="aui-info-item"><small>月咨询' +
                yzx +
                "</small></div>" +
                "</div>" +
                "</div>" +
                "</div>";
              $("#fbf").append(html);
            }
          },
          false
        );
      } else if (result.data.companyType == 3) {
        getStats(3)
        //经纪人
        ajax(
          "/api/v1/broker/brokerInfo",
          "POST",
          { brokerId: result.data.userId },
          function(result) {
            if (result.code == 200) {
              var image = result.data.businessLicenseImg
                ? result.data.businessLicenseImg
                : "static/images/noupload.png";
              var html =
                '<div class="main-info main-info-shadow aui-clearfix" style="padding:.4rem;">' +
                '<div class="aui-list aui-media-list agent">' +
                '<div class="aui-list-item aui-list-item-middle" onclick="toDetail(\'' +
                result.data.user_id +
                "')\">" +
                '<div class="aui-media-list-item-inner">' +
                '<div class="aui-list-item-media" style="width: 4rem;">' +
                '<img src="' +
                getDefaultImg(result.data.headPortrait) +
                '" class="aui-img-round aui-list-img-sm">' +
                "</div>" +
                '<div class="aui-list-item-inner">' +
                '<div class="aui-info">' +
                '<div class="aui-info-item">' +
                '<h4 class="title" style="font-size:.8rem;width:7.5rem;overflow:hidden;text-overflow:ellipsis;white-space: nowrap; !important;display:inline-block;">' +
                result.data.brokerName +
                '</h4><small class="blue-small-tag lightorange">经纪人</small>' +
                "</div>" +
                "</div>" +
                '<div class="aui-info" style="padding-top:.3rem;">' +
                '<div class="aui-info-item color-3"><small>发布中房源：' +
                result.data.houseNum +
                "</small></div>" +
                "</div>" +
                '<div class="aui-info" style="padding-top:.1rem;">' +
                '<div class="aui-info-item color-3">' +
                "<small>近三个月推送楼书：" +
                result.data.buildingBookNum +
                "</small>&nbsp;&nbsp;&nbsp;&nbsp;<small>月咨询：" +
                yzx +
                "</small></div>" +
                "</div>" +
                '<div class="aui-info" style="padding-top:.1rem;">' +
                '<div class="aui-info-item"><small>所属公司：' +
                result.data.companyName +
                "</small></div>" +
                "</div>" +
                "</div>" +
                "</div>" +
                "</div>" +
                '<div class="aui-clearfix" style="width:86%;margin:.3rem auto .5rem;">' +
                '<a href="javascript:;" id="' +
                getDefaultImg(result.data.informationImg) +
                '" onclick="showyyzz(this)" class="for-button aui-pull-left"><img src="static/images/agent-1.svg">从业信息卡</a>' +
                '<a href="javascript:;" id="' +
                image +
                '" onclick="showyyzz(this)" class="for-button aui-pull-right"><img src="static/images/agent-2.svg">营业执照</a>' +
                "</div>" +
                "</div>" +
                "</div>";
              $("#fbf").append(html);
            }
          },
          false
        );
      } else {
        $("#fbf").css({ display: "none" });
      }
    }
  },
  false
);
function getHouseImgs(){
  $("#piclist").empty();
  
  //房源图片
ajax(
  "/api/v1/building/getHouseImgs",
  "POST",
  { houseId: getParams("houseid") },
  function(result) {
    if (result.code == 200) {
      houseInfo.img = getDefaultImg(result.data[0]);
     if(result.data.length <= 0){
      $("#piclist").append(
        '<div class="swiper-slide">' +
          "<img src=" +
          getDefaultImg(result.data[0]) +
          ">" +
          "</div>"
      );
      }else{
        for (var i = 0; i < result.data.length; i++) {
          $("#piclist").append(
            '<div class="swiper-slide">' +
              "<img src=" +
              getDefaultImg(result.data[i]) +
              ">" +
              "</div>"
          );
        }
      }

    }
  },
  false
);
}
getHouseImgs();

doShare(houseInfo.title,houseInfo.desc,houseInfo.img);
function toDetail(id) {
  window.location.href = "/item/views/others/agency.html?id=" + id;
}
function toAsset(id) {
  window.location.href = "/item/views/others/company.html?id=" + id;
}
function toDevelopers() {
  window.location.href =
    "/three/loupan.html?name=" + building3dNo + "&cnt=0&buildid=" + buildingId;
}
//房源周边推荐
ajax(
  "/api/v1/building/recommendedHouseNearby",
  "POST",
  { buildingId: buildid },
  function(result) {
    if (result.code == 200&&result.data != null) {
      var list = [];
      var imgurl1 = fwurl + "/image/";
      for (var j = 0; j < result.data.length; j++) {
        list.push(result.data[j].houseId);
      }
      var zbtjll;
      //周边推荐中房源浏览量集合
      ajax(
        "/api/v1/user/opt/countVisits",
        "POST",
        { ids: list, type: "3" },
        function(result) {
          if (result.code == 200) {
            zbtjll = result;
          }
        },
        false
      );
      for (var i = 0; i < result.data.length; i++) {
        var introducce;
        if (result.data[i].introduce == null) {
          introducce = "";
        } else {
          introducce = result.data[i].introduce;
        }
        if (
          result.data[i].imgUrl == null ||
          result.data[i].imgUrl == "undefined" ||
          result.data[i].imgUrl == "null"
        ) {
          $("#fydfk").append(
            '<div class="out" id="' +
              result.data[i].buildingId +
              '"  onclick=zbtjlp("' +
              result.data[i].houseId +
              '","' +
              result.data[i].building3dCode +
              '",this)>' +
              '<div class="more-house-list">' +
              '<div class="pic">' +
              '<img src="static/images/noupload.png">' +
              '<p class="position-des aui-ellipsis-1"><small>' +
              introducce +
              "</small></p>" +
              "</div>" +
              '<div class="remark aui-clearfix">' +
              '<div class="line-1 aui-ellipsis-1">' +
              result.data[i].houseName +
              "</div>" +
              '<div class="aui-info">' +
              '<div class="aui-info-item"><small>浏览量</small>' +
              zbtjll.data[i].count +
              "</div>" +
              '<div class="aui-info-item"><big>' +
              result.data[i].price +
              "</big><small> 元/m²·天</small></div>" +
              "</div>" +
              "</div>" +
              "</div>" +
              "</div>"
          );
        } else {
          $("#fydfk").append(
            '<div class="out" id="' +
              result.data[i].buildingId +
              '" onclick=zbtjlp("' +
              result.data[i].houseId +
              '","' +
              result.data[i].building3dCode +
              '",this)>' +
              '<div class="more-house-list">' +
              '<div class="pic">' +
              '<img src="' +
              imgurl1 +
              result.data[i].imgUrl +
              '">' +
              '<p class="position-des aui-ellipsis-1"><small>' +
              introducce +
              "</small></p>" +
              "</div>" +
              '<div class="remark aui-clearfix">' +
              '<div class="line-1 aui-ellipsis-1">' +
              result.data[i].houseName +
              "</div>" +
              '<div class="aui-info">' +
              '<div class="aui-info-item"><small>浏览量</small>' +
              zbtjll.data[i].count +
              "</div>" +
              '<div class="aui-info-item"><big>' +
              result.data[i].price +
              "</big><small> 元/m²·天</small></div>" +
              "</div>" +
              "</div>" +
              "</div>" +
              "</div>"
          );
        }
      }
    }
  },
  false
);

//房源周边推荐  下列
/*$.ajax({
	url:fwurl+"/zhixuan/api/v1/building/recommendedBuildingNearby",
	type: "POST",//方法类型
	async : false,
	data:JSON.stringify({buildingId:buildid}),
	headers:{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJjb21wYW55SWRcIjoxMDAwMTE2LFwiY29tcGFueU5hbWVcIjpcIjFcIixcImNvbXBhbnlUeXBlXCI6MCxcImlkXCI6MSxcIm5hbWVcIjpcInRlc3RcIixcInJvbGVDb2RlXCI6XCJST0xFX0NJVFlDRUxMXCJ9IiwiZXhwIjoxNTU5MDE0NTkwfQ.__SUpvjjueT4N7_hJ6ludZnJUGnc3Z3C4GqRIsbiDIc","Content-Type":"application/json;charset=UTF-8","debug":"1"},
	success: function (result) {//
		console.log(result);
    	if(result.code == 200){
    		var imgurl1 = fwurl+"/image/";
    		for(var i=0;i < result.data.length; i++){
    			$("#fydfk").append('<div class="out">'+
    	                '<div class="more-house-list">'+
                        '<div class="pic">'+
                            '<img src="'+imgurl1+result.data[i].imgUrl+'">'+
                            '<p class="position-des aui-ellipsis-1"><small>户型方正，无面积浪费，大玻璃幕墙，采光好</small></p>'+
                        '</div>'+
                        '<div class="remark aui-clearfix">'+
                            '<div class="line-1 aui-ellipsis-1">华贸中心 | 8层 | 300m²</div>'+
                            '<div class="aui-info">'+
                                '<div class="aui-info-item"><small>浏览量</small>39</div>'+
                                '<div class="aui-info-item"><big>'+result.data[i].price+'</big><small> 元/m²·天</small></div>'+
                            '</div>'+
                        '</div>'+
                    '</div>'+
                '</div>');
    			
    		}
    	}
       },
       error : function() {
      	 alert("fail")
       }
   });*/

//浏览量
ajax(
  "/api/v1/user/opt/countVisit",
  "POST",
  { id: houseid, type: "3" },
  function(result) {
    if (result.code == 200) {
      $("#fyyll").html("浏览量" + result.data);
    }
  },
  false
);
//添加浏览量
ajax(
  "/api/v1/user/opt/addVisit",
  "POST",
  { id: houseid, type: "3" },
  function(result) {
    if (result.code == 200) {
      //$("#fyyll").html(result.data);
    }
  },
  false
);
//周边推荐跳转页面
function zbtjlp(houseid, buildname, obj) {
  window.location.href =
    "household.html?name=" +
    buildname +
    "&cnt=0&houseid=" +
    houseid +
    "&buildid=" +
    obj.id;
}
//楼盘概况跳转页面
function lpgk() {
  window.location.href =
    "loupan.html?name=" + building3dNo + "&cnt=0&buildid=" + buildid;
}
function onload(Cesium) {
  if (dzc_service != undefined && commname != "") {
    viewer = new Cesium.Viewer("scenediv1", {
      terrainProvider: new Cesium.CesiumTerrainProvider({
        url: dzc_service.serverurllayers.terrain,
        requestWaterMask: true, //是否请求水面标志位（用于水面特效），默认不请求
        requestVertexNormals: true, //是否请求法线（用于光照效果），默认不请求
        isSct: true //是否为iServer发布的TIN地形服务
      })
    });
    yzfh(roomNo);
    scene = viewer.scene;
    imageryLayers = viewer.imageryLayers;
    //添加影像
    var imageryProvider1 = new Cesium.SuperMapImageryProvider({
      url: dzc_service.serverurllayers.imageWhiteBase
    });
    var widget = viewer.cesiumWidget;
    var layer1 = imageryLayers.addImageryProvider(imageryProvider1);
    var imageryProviderdom = new Cesium.SuperMapImageryProvider({
      url: dzc_service.serverurllayers.Dom["HM"]
    });
    layerdom = imageryLayers.addImageryProvider(imageryProviderdom);
    layerdom.show = false;
    scene.screenSpaceCameraController.enableZoom = false;
    scene.sun.show = false;
    //图片和3D进行按钮切换
    $(".three-d-invisible").on("click", function() {

      var aim = $(this).attr("data-type");
      $(".three-d-a").removeClass("active");
      $('a[name="' + aim + '"]').addClass("active");
      if ($(this).attr("data-type") == "model") {
        $(".model").show();
        $(".picture").hide();
      } else {
        $(".picture").show();
        $(".model").hide();
        setTimeout(function(){
          getHouseImgs();
          var mySwiper = new Swiper(".swiper-container", {
            autoplay: false,
            loop:true,
            direction: "horizontal",
            pagination: {
              el: ".swiper-pagination",
              type: "custom",
              renderCustom: function(swiper, current, total) {
                return current + " / " + total;
              }
            }
          });
        },1500)
      }
    });
    //点击3D楼盘和全景周边按钮切换
    $(".invisible-mode").on("click", function() {
      var aim = $(this).attr("data-type");
      $(".mode-button").removeClass("active");
      $('a[name="' + aim + '"]').addClass("active");
      if ($(this).attr("data-type") == "model-button-2") {
        //全景周边
        btncount = 0;
        viewer.entities.removeAll();
        viewer.entities._show = true;
        promisemodel.then(function(layer) {
          layer.visible = true;
        });
        promisemodel12.then(function(layer) {
          layer.selectEnabled = false;
          layer.visible = true;
        });
        if (commname == "乐成中心" || commname == "BJCY010") {
          promisemodellczx.then(function(layer) {
            layer.selectEnabled = false;
            layer.visible = true;
          });
        }
        layerdom.show = true;
        reset();
        mark(); //全景周边中楼标注
      } else if ($(this).attr("data-type") == "model-button-1") {
        //3D楼盘
        btncount = 1;
        viewer.entities.removeAll();
        viewer.entities._show = true;
        promisemodel.then(function(layer) {
          $("#ditu").css({ display: "none" });
          $("#gif").css({ display: "none" });
          layer.selectEnabled = false;
          layer.visible = true;
        });
        promisemodel12.then(function(layer) {
          layer.selectEnabled = false;
          layer.visible = false;
        });
        if (commname == "乐成中心" || commname == "BJCY010") {
          promisemodellczx.then(function(layer) {
            layer.selectEnabled = false;
            layer.visible = false;
          });
        }
        layerdom.show = false;
        reset();
        louhao();
        var arr = viewer.entities.values;
      }
    });

    //添加鼠标移动事件，功能实现指北针方位和场景方位一致
    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction(function(movement) {
      var heading = scene.camera.heading;
      var ss = (heading * 180) / 3.14;
      document.getElementById("img1").style.transform =
        "rotate(" + -ss + "deg)";
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
      Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
    );

    promisemodel = scene.addS3MTilesLayerByScp(
      dzc_service.serverurllayers.Model["HM"],
      {
        name: "model"
      }
    );
    promisemodel12 = scene.addS3MTilesLayerByScp(
      dzc_service.serverurllayers.Model["HM12"],
      {
        name: "model12"
      }
    );
    if (commname == "BJCY010" || commname == "乐成中心") {
      promisemodellczx = scene.addS3MTilesLayerByScp(
        dzc_service.serverurllayers.Model["LCZX"],
        {
          name: "modellczx"
        }
      );
      promisemodellczx.then(function(layer) {
        layer.selectEnabled = false;
        layer.visible = false;
      });
    }
    promisemodel12.then(function(layer) {
      layer.selectEnabled = false;
      layer.visible = false;
      layer.lodRangeScale = 0.2;
    });
    promisemodel.then(function(layer) {
      $("#ditu").css({ display: "none" });
      $("#gif").css({ display: "none" });
      layer.selectEnabled = false;
      layer.visible = true;
      layer.lodRangeScale = 0.2;
    });
    /* var array1 = [];
			 array1.push(hsid);*/
    promisehouse = scene.addS3MTilesLayerByScp(
      dzc_service.serverurllayers.Household,
      {
        name: "household"
      }
    );
    promisehouse.then(function(layer) {
      layer.setQueryParameter({
        //设置查询参数
        url: dataurl,
        dataSourceName: "AttachData", //数据源
        dataSetName: "Household" //数据集
      });
      layer._selectColorType = 1;
      layer.selectEnabled = true;
      layer.visible = true;
      layer.setObjsVisible(array, true);
      layer.setObjsColor(array, new Cesium.Color(0, 139 / 255, 210 / 255, 1));
    });
    //yzfh(hsid);
    if (btncount == 0) {
      Range = 474;
      var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
        Cesium.Cartesian3.fromDegrees(
          center.x - 0.00000000045916,
          center.y,
          tranheight
        )
      );
      var heading = Cesium.Math.toRadians(parseInt(lpheading));
      var pitch = Cesium.Math.toRadians(-35.0);
      var range = 474.0;
      scene.camera.lookAtTransform(
        transform,
        new Cesium.HeadingPitchRange(heading, pitch, range)
      );
    } else {
      Range = range1;
      var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
        Cesium.Cartesian3.fromDegrees(
          center.x - 0.00000000045916,
          center.y,
          tranheight
        )
      );
      var heading = Cesium.Math.toRadians(Number(lpheading));
      var pitch = Cesium.Math.toRadians(pitchcsh);
      var range = range1;
      scene.camera.lookAtTransform(
        transform,
        new Cesium.HeadingPitchRange(heading, pitch, range)
      );
    }

    //getFeaturesBySQLcommunity(commname);
    louhao(); //展示出楼号（T1，T2,T3）
  } else {
    $("#scenediv1").css({ display: "none" });
    $("#ditu").css({ display: "none" });
    $("#gif").css({ display: "none" });
    $("#model3d").css({ display: "none" });
    $("#tp").addClass("active");
    $(".three-d-invisible").css({ display: "none" });
  }
}
//初始化显示户
function yzfh(RoomNo) {
  var str = "";
  str = str + " RoomNo = '" + RoomNo + "' and LPBH = '"+commname+"'";

  var string = "";
  var sql = str;
  var queryconfig = {
    url: dataurl,
    sql: sql,
    layerName: dzc_service.layers.layerhousehold,
    datalayerName: dzc_service.datalayers.layerhousehold,
    callback: processCompletedhouse
  };
  _queryBySql(queryconfig);
}
function processCompletedhouse(getFeaturesEventArgs) {
  var array = [];
  var list = getFeaturesEventArgs.originResult.features;
  var count = getFeaturesEventArgs.originResult.featureCount;
  for (var j = 0; j < list.length; j++) {
    var smid = getFeaturesEventArgs.originResult.features[j].ID;
    array.push(smid);
  }
  if (count > 0) {
    promisehouse.then(function(layer) {
      layer._selectColorType = 1;
      layer.selectEnabled = true;
      layer.visible = true;
      layer.setObjsVisible(array, true);
      layer.setObjsColor(array, new Cesium.Color(0, 139 / 255, 210 / 255, 1));
    });
  }
}

//根据不同小区进行相机定位
function camera(height, head, pit, ran, head1, pit1, ran1) {
  if (btncount == 0) {
    Range = 474;
    var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
      Cesium.Cartesian3.fromDegrees(
        center.x - 0.00000000045916,
        center.y,
        height
      )
    );
    var heading = Cesium.Math.toRadians(head);
    var pitch = Cesium.Math.toRadians(pit);
    var range = ran;
    scene.camera.lookAtTransform(
      transform,
      new Cesium.HeadingPitchRange(heading, pitch, range)
    );
  } else {
    Range = 350;
    var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
      Cesium.Cartesian3.fromDegrees(
        center.x - 0.00000000045916,
        center.y,
        height
      )
    );
    var heading = Cesium.Math.toRadians(head1);
    var pitch = Cesium.Math.toRadians(pit1);
    var range = ran1;
    scene.camera.lookAtTransform(
      transform,
      new Cesium.HeadingPitchRange(heading, pitch, range)
    );
  }
}
/**
 * 放大按钮：根据相机的拉近，实现模型的放大效果
 */
function add() {
  $("#fy").attr("src", "images/fuyuan.png");
  $("#fd").attr("src", "images/fda1.png");
  $("#sx").attr("src", "images/suoxiao.png");
  var heading, pitch;
  if (btncount == 0) {
    heading = scene.camera.heading;
    //pitch = Cesium.Math.toRadians(-35.0);
    pitch = scene.camera.pitch;
  } else {
    heading = scene.camera.heading;
    //pitch = Cesium.Math.toRadians(-5.0);
    pitch = scene.camera.pitch;
  }
  var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(
      center.x - 0.00000000045916,
      center.y,
      tranheight + 10
    )
  );
  if (Range < 475 && Range > Rangeheight) {
    Range = Range - 30;
    scene.camera.lookAtTransform(
      transform,
      new Cesium.HeadingPitchRange(heading, pitch, Range)
    );
  } else {
    if (Range > 455) {
      Range = 455;
      scene.camera.lookAtTransform(
        transform,
        new Cesium.HeadingPitchRange(heading, pitch, Range)
      );
    } else if (Range < Rangeheight) {
      Range = Rangeheight;
    } else {
      Range = Rangeheight;
    }
  }
}
/**
 * 缩小按钮：根据相机的远离，使看到的模型缩小
 */
function reduce() {
  var heading, pitch;
  if (btncount == 0) {
    heading = scene.camera.heading;
    //pitch = Cesium.Math.toRadians(-35.0);
    pitch = scene.camera.pitch;
  } else {
    heading = scene.camera.heading;
    //pitch = Cesium.Math.toRadians(-5.0);
    pitch = scene.camera.pitch;
  }
  $("#fy").attr("src", "images/fuyuan.png");
  $("#fd").attr("src", "images/fangda.png");
  $("#sx").attr("src", "images/sxiao1.png");
  var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(
      center.x - 0.00000000045916,
      center.y,
      tranheight + 10
    )
  );
  if (Range <= 455 && Range >= Rangeheight) {
    Range = Range + 30;
    scene.camera.lookAtTransform(
      transform,
      new Cesium.HeadingPitchRange(heading, pitch, Range)
    );
  } else {
    if (Range > 455) {
      Range = 455;
    } else {
      Range = Rangeheight;
      scene.camera.lookAtTransform(
        transform,
        new Cesium.HeadingPitchRange(heading, pitch, Range)
      );
    }
  }
}
/**
 * 复原按钮：初始化场景中相机的方位角和高度
 */
function reset() {
  $("#fy").attr("src", "images/hyuan1.png");
  $("#fd").attr("src", "images/fangda.png");
  $("#sx").attr("src", "images/suoxiao.png");

  Value = 202;
  var pitch;
  if (btncount == 0) {
    pitch = Cesium.Math.toRadians(-35.0);
    //pitch = scene.camera.pitch;
    Range = 474;
  } else {
    pitch = Cesium.Math.toRadians(pitchcsh);
    //pitch = scene.camera.pitch;
    Range = range1;
  }
  var transform = Cesium.Transforms.eastNorthUpToFixedFrame(
    Cesium.Cartesian3.fromDegrees(
      center.x + 0.00000000001114,
      center.y,
      tranheight + 10
    )
  );
  var heading = Cesium.Math.toRadians(lpheading);

  //var pitch = Cesium.Math.toRadians(-5.0);
  var range2 = Range;
  scene.camera.lookAtTransform(
    transform,
    new Cesium.HeadingPitchRange(heading, pitch, range2)
  );
}

/**
 * 功能：缓冲区查询
 * @param distance
 */
function buff() {
  $("#ditu").css({ display: "none" });
  $("#gif").css({ display: "none" });
  layerdom.show = true;
  //纹理房屋模型
  promisemodel.then(function(layer) {
    layer.lodRangeScale = 0.4;
    layer.visible = true;
    layer.setObjsVisible([-1], false); //设置建筑物id为-1的隐藏，其余所有建筑物可见
  });
  reset();
  mark(); //全景周边中楼标注
}

//从业信息卡，营业执照
function showyyzz(url) {
  var src;
  if (url.id == null || url.id == "undefined" || url.id == "null") {
    src = "static/images/noupload.png";
  } else {
    src = url.id;
  }
  $("#bigimg").attr("src", src); //设置#bigimg元素的src属性

  /*获取当前点击图片的真实大小，并显示弹出层及大图*/

  $("<img/>")
    .attr("src", src)
    .load(function() {
      var windowW = $(window).width(); //获取当前窗口宽度
      var windowH = $(window).height(); //获取当前窗口高度
      var realWidth = this.width; //获取图片真实宽度
      var realHeight = this.height; //获取图片真实高度
      var imgWidth, imgHeight;
      var scale = 0.8; //缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

      if (realHeight > windowH * scale) {
        //判断图片高度
        imgHeight = windowH * scale; //如大于窗口高度，图片高度进行缩放
        imgWidth = (imgHeight / realHeight) * realWidth; //等比例缩放宽度
        if (imgWidth > windowW * scale) {
          //如宽度扔大于窗口宽度
          imgWidth = windowW * scale; //再对宽度进行缩放
        }
      } else if (realWidth > windowW * scale) {
        //如图片高度合适，判断图片宽度
        imgWidth = windowW * scale; //如大于窗口宽度，图片宽度进行缩放
        imgHeight = (imgWidth / realWidth) * realHeight; //等比例缩放高度
      } else {
        //如果图片真实高度和宽度都符合要求，高宽不变
        imgWidth = realWidth;
        imgHeight = realHeight;
      }
      $(bigimg).css("width", imgWidth); //以最终的宽度对图片缩放

      var w = (windowW - imgWidth) / 2; //计算图片与窗口左边距
      var h = (windowH - imgHeight) / 2; //计算图片与窗口上边距
      $(innerdiv).css({ top: h, left: w }); //设置#innerdiv的top和left属性
      $(outerdiv).fadeIn("fast"); //淡入显示#outerdiv及.pimg
    });

  $(outerdiv).click(function() {
    //再次点击淡出消失弹出层
    $(this).fadeOut("fast");
  });
}

//查询出浏览量和房源信息
function queryinfo() {
  $.ajax({
    url: htmlUrl + "/ZX3DS/sys/cjfy/getxmxq",
    type: "POST", //方法类型
    data: { community: commname },
    dataType: "json", //预期服务器返回的数据类型
    async: false,
    success: function(result) {
      var jcnd = result.result[0].jcsj;
      var niandai = jcnd.indexOf("-");
      var nd = jcnd.substring(0, niandai);
      $("#jcnd").html(nd + "年");
      $("#jzmj").html(result.result[0].zjzmj);
      $("#sssq").html(result.result[0].sssq);
      $("#ldsl").html(result.result[0].ldzs);
      $("#zglc").html(result.result[0].zglc);
      $("#szhx").html(result.result[0].szhx);
      $("#kfs").html(result.result[0].kfs);
      $("#lpdz").html(result.result[0].adress);
      $("#wyf").html(result.result[0].wyf);
      /* for(var m=0;m<result.result3.length;m++){
		    		 var path3=result.result3[m].path;
			 			$("#piclist").append('<div class="swiper-slide">'+
		                    '<a href="'+path+path3+'" data-size="1024x1024"><img src="'+path+path3+'" /></a>'+
		                    '<figcaption itemprop="caption description">图片"'+m+'"</figcaption>'+
		                '</div>');
		    	 } */
    },
    error: function() {
      alert("fail");
    }
  });
  $.ajax({
    url: htmlUrl + "/ZX3DS/sys/cjfy/gethousemess",
    type: "POST", //方法类型
    dataType: "json", //预期服务器返回的数据类型
    data: { id: fjid[0] },
    async: false,
    success: function(result) {
      for (var i = 0; i < result.result.length; i++) {
        var path3 = result.result[i].path;
        $("#piclist").append(
          '<div class="swiper-slide">' +
            '<a href="' +
            path +
            path3 +
            '" data-size="1024x1024"><img src="' +
            path +
            path3 +
            '" /></a>' +
            '<figcaption itemprop="caption description">图片"' +
            i +
            '"</figcaption>' +
            "</div>"
        );
      }
    },
    error: function() {
      alert("失败");
    }
  });
  //浏览量量
  $.ajax({
    url: htmlUrl + "/ZX3DS/sys/wyslb/getwyslb",
    type: "POST", //方法类型
    dataType: "json", //预期服务器返回的数据类型
    data: { url: fjid[0] },
    async: false,
    success: function(result) {
      $("#yll").html(result.result);
    },
    error: function() {
      alert("失败");
    }
  });
  $.ajax({
    url: htmlUrl + "/ZX3DS/sys/llb/getllb",
    type: "POST", //方法类型
    dataType: "json", //预期服务器返回的数据类型
    data: { url: fjid[0] },
    async: false,
    success: function(result) {
      console.log(result);
    },
    error: function() {
      alert("失败");
    }
  });
}

//3D楼盘展示出楼号
function louhao() {
  $.ajax({
    url: "js/js/marker.json",
    type: "GET",
    dataType: "json",
    async: false,
    success: function(data) {
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].louhao.length; j++) {
            var temp = data[i].datas[0].louhao[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].louhao[j].id,
              name: data[i].datas[0].louhao[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              label: {
                //文字标签
                text: data[i].datas[0].louhao[j].text,
                outlineWidth: 0,
                outlineColor: Cesium.Color.WHITE,
                showBackground: true,
                backgroundColor: new Cesium.Color(0, 0, 0, 0.4),
                fillColor: Cesium.Color.WHITE,
                font: "18px SimHei",
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直方向以底部来计算标签的位置
                pixelOffset: new Cesium.Cartesian2(0, -9) //偏移量
              }
            });
          }
        }
      }
    }
  });
}
//全景周边中标注
function mark() {
  $.ajax({
    url: "js/js/marker.json",
    type: "GET",
    dataType: "json",
    async: false,
    success: function(data) {
      //添加文字和图片
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].wenimg.length; j++) {
            var temp = data[i].datas[0].wenimg[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var temp1 = data[i].datas[0].wenimg[j].pixelOffset;
            var result1 = temp1.split(",");
            if (result1.length > 0) {
              var left = result1[0];
              var right = result1[1];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].wenimg[j].id,
              name: data[i].datas[0].wenimg[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              billboard: {
                image: data[i].datas[0].wenimg[j].billboard,
                width: 32,
                height: 32
              },
              label: {
                //文字标签
                text: data[i].datas[0].wenimg[j].text,
                outlineWidth: 0,
                outlineColor: Cesium.Color.YELLOW,
                showBackground: true,
                backgroundColor: new Cesium.Color(0, 0, 0, 0.4),
                fillColor: Cesium.Color.YELLOW,
                font: "20px SimHei",
                verticalOrigin: Cesium.VerticalOrigin.LEFT, //垂直方向以底部来计算标签的位置
                pixelOffset: new Cesium.Cartesian2(
                  parseFloat(left),
                  parseFloat(right)
                ) //偏移量
              }
            });
          }
        }
      }
      //添加图片
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].img.length; j++) {
            var temp = data[i].datas[0].img[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].img[j].id,
              name: data[i].datas[0].img[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              billboard: {
                //图标
                image: data[i].datas[0].img[j].image,
                width: 32,
                height: 32
              }
            });
          }
        }
      }
      //添加楼号
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].louhao.length; j++) {
            var temp = data[i].datas[0].louhao[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].louhao[j].id,
              name: data[i].datas[0].louhao[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              label: {
                //文字标签
                text: data[i].datas[0].louhao[j].text,
                outlineWidth: 0,
                outlineColor: Cesium.Color.WHITE,
                showBackground: true,
                backgroundColor: new Cesium.Color(0, 0, 0, 0.4),
                fillColor: Cesium.Color.WHITE,
                font: "18px SimHei",
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直方向以底部来计算标签的位置
                pixelOffset: new Cesium.Cartesian2(0, -9) //偏移量
              }
            });
          }
        }
      }
      //添加文本
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].wenben.length; j++) {
            var temp = data[i].datas[0].wenben[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].wenben[j].id,
              name: data[i].datas[0].wenben[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              label: {
                //文字标签
                text: data[i].datas[0].wenben[j].text,
                outlineWidth: 0,
                outlineColor: Cesium.Color.YELLOW,
                showBackground: true,
                backgroundColor: new Cesium.Color(0, 0, 0, 0.4),
                fillColor: Cesium.Color.YELLOW,
                font: "20px SimHei",
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直方向以底部来计算标签的位置
                pixelOffset: new Cesium.Cartesian2(0, -9) //偏移量
              }
            });
          }
        }
      }

      //添加道路
      for (var i = 0; i < data.length; i++) {
        if (commname == data[i].name) {
          for (var j = 0; j < data[i].datas[0].daolu.length; j++) {
            var temp = data[i].datas[0].daolu[j].position;
            var result = temp.split(",");
            if (result.length > 0) {
              var long = result[0];
              var lat = result[1];
              var height = result[2];
            }
            var citizensBankPark = viewer.entities.add({
              id: data[i].datas[0].daolu[j].id,
              name: data[i].datas[0].daolu[j].name,
              position: Cesium.Cartesian3.fromDegrees(
                parseFloat(long),
                parseFloat(lat),
                parseFloat(height)
              ),
              label: {
                //文字标签
                text: data[i].datas[0].daolu[j].text,
                outlineWidth: 1,
                outlineColor: Cesium.Color.LIME,
                showBackground: true,
                backgroundColor: new Cesium.Color(0, 0, 0, 0.4),
                fillColor: Cesium.Color.LIME,

                font: "20px SimHei",
                verticalOrigin: Cesium.VerticalOrigin.BOTTOM, //垂直方向以底部来计算标签的位置
                pixelOffset: new Cesium.Cartesian2(0, -9) //偏移量
              }
            });
          }
        }
      }
    }
  });
}

